{% extends "analysis_plugins/general_information.html" %}


{% macro device_tree_table_cell(dt_data, colspan="1") %}
    <td colspan="{{ colspan }}">
        <pre class="dt-pre">{{ dt_data | hide_dts_binary_data | nice_generic | safe }}</pre>
    </td>
{% endmacro %}


{% block styles %}
    <style>
         .dt-pre {
            padding: 5px;
            width: 100%;
            white-space: pre-wrap;
            overflow-y: scroll;
            overflow-x: hidden;
            display: block;
            font-family: monospace;
            margin: 0 0;
            max-height: 768px;
         }
    </style>
    <script src="{{ url_for('static', filename='highlight.js/languages/dts.min.js') }}"></script>
    <script>
        async function async_highlight(element) {
            element.innerHTML = hljs.highlight(
                element.innerHTML.replaceAll("&lt;", "<").replaceAll("&gt;", ">"),
                {language: 'dts'}
            ).value;
        };
        document.addEventListener('DOMContentLoaded', (event) => {
            document.querySelectorAll('.dt-pre').forEach((element) => {
                async_highlight(element);
            });
        });
    </script>
{% endblock %}


{% block analysis_result_details %}

{# Don't break on legacy result #}
{% if "device_tree" in analysis_result %}
    <tr class="table-warning">
        <td> Deprecation Warning </td>
        <td> Analysis version is deprecated, please update the analysis </td>
    </tr>
    <tr>
        <td> Device Tree </td>
        {{ device_tree_table_cell(analysis_result.device_tree, "1") }}
    </tr>
{% endif %}

{% for dt_dict in analysis_result.get("device_trees", []) %}
    <tr data-toggle="collapse" data-target="#collapse-{{ dt_dict.offset }}">
        <td class="clickable" colspan=2>
            <i class="fas fa-angle-down"></i>
            Offset {{ dt_dict.offset | hex }} | {{ dt_dict.model or dt_dict.description or "" }}
        </td>
    </tr>
    <tr>
        <td colspan="2" class="qemu-td p-0">
            <div class="collapse" id="collapse-{{ dt_dict.offset }}">
                <table class="table table-bordered table-sm m-0" style="width: 100%">
                    {% for key, value in dt_dict.header.items() -%}
                        <tr>
                            <td width="200px">{{ key | replace_underscore }}</td>
                            <td width="125px">{{ value | nice_number }}</td>
                            <td>{{ value | hex }}</td>
                        </tr>
                    {%- endfor %}
                    <tr>
                        {{ device_tree_table_cell(dt_dict.device_tree, "3") }}
                    </tr>
                </table>
            </div>
        </td>
    </tr>
{% endfor %}

{% endblock %}
